import { logins } from "@/until/http";
export default {
    namespaced:true,
    state:{
        get token(){
        return sessionStorage.getItem('token')||''
        },
        set token(v){
         if(v){
            sessionStorage.setItem('token',v)
         }else{
            sessionStorage.removeItem('token')
         }
        }
    },
    mutations:{
        set_token(state,t){
            state.token=t
        },
        del_token(state){
            state.token=''
        }
    },
    actions:{
        async denglu({commit},obj){
            const {data:res}=await logins(obj)
            if(res.meta.status==200){
                commit('set_token',res.data.token)
                return Promise.resolve(res.meta.msg)
            }else{
                return Promise.reject(res.meta.msg)
            }
        }
    }
}